package org.ainlolcat.ainscience.statistics;

import org.ainlolcat.ainscience.entity.Entity;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.util.Hashtable;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author ainlolcat
 * Date: 11/5/11
 */
public class StaticticsTableModel implements TableModel{
    Map<String,String> data = new TreeMap();

    public StaticticsTableModel(Entity entity){
        try {
            data.putAll(new StatisticsCollectorImpl(entity).collect());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public int getRowCount() {
        return data.size();
    }

    public int getColumnCount() {
        return 2;
    }

    public String getColumnName(int i) {
        if (i==0) return "name";
        if (i==1) return "value";
        return "undef";
    }

    public Class<?> getColumnClass(int i) {
        return String.class;
    }

    public boolean isCellEditable(int i, int i1) {
        return false;
    }

    public Object getValueAt(int i, int i1) {
        if (i1==0){
            return data.keySet().toArray()[i];
        } else if (i1==1){
            return data.values().toArray()[i];
        }
        return null;
    }

    public void setValueAt(Object o, int i, int i1) {
    }

    public void addTableModelListener(TableModelListener tableModelListener) {
    }

    public void removeTableModelListener(TableModelListener tableModelListener) {
    }
}
